﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MingYuanYun.DependencyInjection;
using MingYuanYun.StructuredLog.Abstractions;
using MingYuanYun.StructuredLog.NLog;

namespace MingYuanYun.WebApi.Logging
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddStructuredNLog(this IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<MyLoggerOptions>(configuration.GetSection("Logging:MyLoggerOptions"));
            services.Configure<RequestLogOptions>(configuration.GetSection("Logging:RequestLogOptions"));

            services.AddScoped<IMyLogger, MyLogger>(p => new MyLogger(p.GetOptions<MyLoggerOptions>()));

            return services;
        }
    }
}
